﻿using System;
using System.Linq;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

using Ah.Testudin.Engine.Graphics;
using Ah.Testudin.Engine.Events;

namespace Ah.Testudin.Engine.UI.Elements
{
    public class MainMenuScreenElement : ScreenElementBase
    {
        #region Private Member Variables

        private readonly IEventManager _eventManager;

        private readonly ITestudinRenderer _renderer;

        private readonly SpriteFont _spriteFont;

        #endregion

        #region Constructors

        public MainMenuScreenElement(
            Vector2 position,
            int width,
            int height,
            SpriteFont spriteFont)
            : base(position, width, height)
        {
            _spriteFont = spriteFont;

            _eventManager = EventManagerSingleton.Instance;

            _renderer = GraphicsDeviceRendererSingleton.Instance;
        }

        #endregion

        #region ScreenElementBase

        public override short ZOrder
        {
            get { return 100; }
        }

        public override bool Visible
        {
            get { return true; }
        }

        public override bool ProcessInput()
        {
            KeyboardState kbState = Keyboard.GetState();

            if (kbState.GetPressedKeys().Contains(Keys.Enter))
            {
                _eventManager.TriggerEvent(new GameStartedEvent());

                return true;
            }

            return false;
        }

        public override void Update(GameTime gameTime)
        {
            // DO NOTHING
        }

        public override void Render()
        {
            _renderer.Clear(Color.Black);

            _renderer.BeginSpriteBatch();

            _renderer.RenderString(
                _spriteFont,
                "Press ENTER to start a new game",
                new Vector2(
                    80,
                    80),
                Color.Red);

            _renderer.EndSpriteBatch();
        }

        #endregion
    }
}
